{include file="public/head"}
<body style="background:#eee">

<header class="aui-header-default aui-header-fixed aui-header-bg">
    <a href="javascript:history.back(-1)" class="aui-header-item">
        <i class="aui-icon aui-icon-back-white"></i>
    </a>
    <div class="aui-header-center aui-header-center-clear">
        <div class="aui-header-center-logo">
            <div class="aui-car-white-Typeface" style="color:black;font-weight: bold;">收货地址</div>
        </div>
    </div>
    <a href="#" class="aui-header-item-icon"   style="min-width:0">
        <!--<i class="aui-icon aui-icon-search"></i>-->
    </a>
</header>

<section class="aui-myOrder-content">
    {volist name="AddressList" id="v"}
    <div class="aui-Address-box">
        <div class="aui-Address-box-item">
            <div class="aui-Address-box-item-bd">
                <p>{$v.name}</p>
            </div>
            <div class="aui-Address-box-item-ft">
                <p>{$v.phone}</p>
            </div>
        </div>
        <div class="aui-Address-box-item">
            <div class="aui-Address-box-item-bd">
                <p>{$v.area}{$v.address}</p>
            </div>
        </div>
        <div class="aui-Address-box-item">
            <div class="aui-Address-box-item-bd">
                <p><input type="checkbox" address_id="{$v.id}" class="check goods-check goodsCheck" {if condition="$v.is_default eq 1"}checked="checked"{/if} style="background-size: 17px 17px;"> <em style="padding-left:24px;">默认地址</em></p>
            </div>
            <div class="aui-Address-box-item-ft">
                <p class="delete" address_id="{$v.id}">删除</p>
            </div>
        </div>
    </div>
    {/volist}
    <div class="aui-out">
        <a href="{:url('User/AddressAdd',['goods_id'=>$goods_id])}">新建收货地址</a>
    </div>
</section>


<script type="text/javascript" src="__STATIC__/User/js/jquery.min.js"></script>
<script type="text/javascript" src="__STATIC__/User/js/aui.js"></script>
<script type="text/javascript" >
    $(function () {
        //设置默认地址
        $(".check").on('change',function () {
            var address_id = $(this).attr('address_id');
            $.ajax({
                type:"POST",
                url:"{:url('User/AddressDefault')}",
                data:{
                    address_id:address_id,
                },
                dataType:"json",
                success:function(data){
                    if(data.status == 1){
                        // alert(data.message);
                        // window.location.reload();
                    }else{
                        alert(data.message);
                    }
                }
            })
        })

        //删除地址
        $(".delete").on('click',function () {
            var address_id = $(this).attr('address_id');
            $.ajax({
                type:"POST",
                url:"{:url('User/AddressDelete')}",
                data:{
                    address_id:address_id,
                },
                dataType:"json",
                success:function(data){
                    if(data.status == 1){
                        alert(data.message);
                        window.location.reload();
                    }else{
                        alert(data.message);
                    }
                }
            })
        })
    })
</script>

</body>
</html>